package scriptEngine

import (
	"gitee.com/fierce_wolf/go-fox-edge-common/commUtil/Map"
	"github.com/dop251/goja"
)

func HasScriptEngine(manufacturer string, deviceType string, operateMode string) bool {
	mutex.Lock()
	defer mutex.Unlock()

	vm, _ := Map.GetValue(engineMap, manufacturer, deviceType, operateMode)
	return vm != nil
}

func GetScriptEngine(manufacturer string, deviceType string, operateMode string) *goja.Runtime {
	mutex.Lock()
	defer mutex.Unlock()

	vm, _ := Map.GetValue(engineMap, manufacturer, deviceType, operateMode)
	if vm != nil {
		return vm.(*goja.Runtime)
	}

	engine := goja.New()
	Map.SetValue(engineMap, manufacturer, deviceType, operateMode, engine)
	return engine
}
